#include <stdio.h>
#include <stdarg.h>

float maximum(const char *format, ...)
{
	int maxint = 0;
	int tmp_maxint = 0;

	float maxfloat = 0.0;
	float tmp_maxfloat = 0.0;

	va_list ap; /* declare an argument pointer to a variable arg list */
	va_start(ap,format); /* initialise the arg pointer using the last know arg */

	const char *p = format;

	while(*p) {
		switch (*p) {
		case 'i':
			tmp_maxint = va_arg(ap,int); // va_arg returns the current argument
			if (tmp_maxint > maxint) {
				maxint = tmp_maxint;
			}
			++p;
			continue;
		case 'f':
			tmp_maxfloat = va_arg(ap,double);
			if (tmp_maxfloat > maxfloat) {
				maxfloat = tmp_maxfloat;
			}
			++p;
			continue;
		default:
			++p;
			continue;
		} // switch
	} // while

	va_end(ap); /* restore any special stack manipulations */

	if (*format == 'i') {
		return (maxint);
	} else if (*format == 'f') {
		return (maxfloat);
	}

	return (0);
} // maximum



int main()
{
	float max;
	max = maximum("iiiii",431,276,2,5,54);
	printf("\nMax = %d\n",(int)max);
	max = maximum("fff",1.2,4.5,5.54);
	printf("\nMax = %d\n",max);

	return 0;
} // main
